/**
 * @author Steve Gao<gaofu@parllay.com>
 */
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class WallPhotosFrontendHandler extends BaseHandler {

    get pattern() {
        return '/me/walls/:wall_id/users';
    }

    doGET(request, response) {
        if(!request.session.user.authenticated) {
            response.end(JSON.stringify([]));
            return;
        }
        var count = request.query.count || 100;
        var type = request.query.type || 'new'; //new or old
        var since = request.query.since || 'now';
        var order = (request.query.order || 'desc').toLowerCase(); // desc | asc, default order is desc
        var searchWord = request.query.q || null;
        var source = request.query.source || null;
        var wallId = request.params.wall_id;
        var userId = request.session.user.id;
        this.Controller.getWallUsersByWallId(wallId, {
            count: count,
            type: type,
            since: since,
            order: order,
            searchWord: searchWord,
            source: source,
            userId: userId
        }, (result) => {
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = WallPhotosFrontendHandler;